package com.woniuxy.hotel.room.mapper;

import com.woniuxy.hotel.room.pojo.Room;
import com.woniuxy.hotel.room.pojo.RoomType;
import com.woniuxy.hotel.room.pojo.RoomTypeExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface RoomTypeMapper {
    /**
     * 依条件统计
     *
     * @param example 条件类
     * @return
     */
    @SelectProvider(type = RoomTypeSqlProvider.class, method = "countByExample")
    int countByExample(RoomTypeExample example);
    
    @DeleteProvider(type = RoomTypeSqlProvider.class, method = "deleteByExample")
    int deleteByExample(RoomTypeExample example);
    
    /**
     * 依主键删除
     *
     * @param roomtypeid 主键id
     * @return
     */
    @Delete({
            "delete from roomType",
            "where roomTypeId = #{roomtypeid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer roomtypeid);
    
    /**
     * 全类插入（不建议使用）
     *
     * @param record 实体类
     * @return
     */
    @Insert({
            "insert into roomType (roomTypeId, roomType)",
            "values (#{roomtypeid,jdbcType=INTEGER}, #{roomtype,jdbcType=VARCHAR})"
    })
    int insert(RoomType record);
    
    /**
     * 依参数插入
     *
     * @param record 实体类
     * @return
     */
    @InsertProvider(type = RoomTypeSqlProvider.class, method = "insertSelective")
    int insertSelective(RoomType record);
    
    @SelectProvider(type = RoomTypeSqlProvider.class, method = "selectByExample")
    @Results({
            @Result(column = "roomTypeId", property = "roomtypeid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "roomPrice", property = "roomprice", jdbcType = JdbcType.DOUBLE),
            @Result(column = "roomType", property = "roomtype", jdbcType = JdbcType.VARCHAR)
    })
    List<RoomType> selectByExample(RoomTypeExample example);
    
    /**
     * 依主键查询
     * @param roomtypeid 主键
     * @return
     */
    @Select({
            "select",
            "*",
            "from roomType",
            "where roomTypeId = #{roomtypeid,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column = "roomTypeId", property = "roomtypeid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "roomPrice", property = "roomprice", jdbcType = JdbcType.DOUBLE),
            @Result(column = "roomType", property = "roomtype", jdbcType = JdbcType.VARCHAR)
    })
    RoomType selectByPrimaryKey(Integer roomtypeid);
    
    @UpdateProvider(type = RoomTypeSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") RoomType record, @Param("example") RoomTypeExample example);
    
    @UpdateProvider(type = RoomTypeSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") RoomType record, @Param("example") RoomTypeExample example);
    
    /**
     * 依主键按属性修改
     *
     * @param record 实体类
     * @return
     */
    @UpdateProvider(type = RoomTypeSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(RoomType record);
    
    /**
     * 依主键修改
     * @param record 实体类
     * @return
     */
    @Update({
            "update roomType",
            "set roomType = #{roomtype,jdbcType=VARCHAR},",
            "roomPrice = #{roomprice,jdbcType=DOUBLE}",
            "where roomTypeId = #{roomtypeid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(RoomType record);



    /**
     * 查询房间类型房间
     * @param room_type_id
     * @return
     */
    @Select("select * from room where roomTypeId =#{room_type_id} and roomFlag = 0")
    List<Room> findRoomsByRoomTypeId(Integer room_type_id);

    @Select("select * from roomType where roomtypeid=#{roomtype}")
    RoomType findRoomType(Integer roomtypeid);
    
}